//
//  MCOrderListSectionHeaderView.swift
//  StoreManage
//
//  Created by MC on 2017/12/21.
//  Copyright © 2017年 MC. All rights reserved.
//

import UIKit

class MCOrderListSectionHeaderView: UIView {

    
    var model = MCOrderListFatherModel() {
        didSet {
            orderLabel.text = "订单编号: " + model.orderSn
            
            
            
            /** 状态
              如果是配送方式为2，并且是自提情况下，   订单状态是4或者6，就是已核销，否则是未核销
             */
            if model.deliveryWay.intValue == 2 && model.isSelfDelivery.intValue == 1 {
                if model.status.intValue == 4 || model.status.intValue == 6 {
                    statusLabel.text = "已核销"
                } else {
                    statusLabel.text = "未核销"
                }
            } else {
                switch model.status {
                case 2:
                    statusLabel.text = "待发货"
                case 3:
                    statusLabel.text = "待收货"
                case 4:
                    statusLabel.text = "已完成"
                case 5:
                    statusLabel.text = "已取消"
                case 6:
                    statusLabel.text = "交易成功"
                case 7:
                    statusLabel.text = "已关闭"
                default:
                    break
                }
            }
            
            
            
            contactLabel.text = model.linkMan + " " + model.mobile
            
            // 配送方式
            switch model.deliveryWay.intValue {
            case 1:   // 及时送
                wayLabel.text = "及时送"
            case 2:   // 到店取（或自提)
                if model.isSelfDelivery.intValue == 1 {
                    wayLabel.text = "自提"
                } else {
                    wayLabel.text = "到店取"
                }
            case 3:   // 快递送
                wayLabel.text = "快递送"
            default:
                wayLabel.text = ""
            }
            
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.white
        setUpSubViews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUpSubViews() {
       
        self.addSubview(lineView)
        lineView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(15)
            make.centerY.equalTo(self)
            make.size.equalTo(CGSize.init(width: 4, height: 28))
        }
        
        self.addSubview(orderLabel)
        orderLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(lineView.snp.right).offset(7)
            make.bottom.equalTo(self.snp.centerY).offset(-2)
        }
        
        self.addSubview(contactLabel)
        contactLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(lineView.snp.right).offset(7)
            make.top.equalTo(self.snp.centerY).offset(2)
        }

        
        self.addSubview(statusLabel)
        statusLabel.snp.remakeConstraints { (make) ->Void in
            make.right.equalTo(-15)
            make.bottom.equalTo(self.snp.centerY).offset(-2)
        }
        
        self.addSubview(wayLabel)
        wayLabel.snp.remakeConstraints { (make) ->Void in
            make.right.equalTo(-15)
            make.top.equalTo(self.snp.centerY).offset(2)
        }
    }

    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.MCGray_middle
        return view
    }()

    
    public lazy var orderLabel: UILabel = {
        let label = UILabel.init()
        label.font = MCFont(13)
        label.textColor = UIColor.MCWords
        label.text = "订单编号： "
        return label
    }()
    
    public lazy var contactLabel: UILabel = {
        let label = UILabel.init()
        label.font = MCFont(12)
        label.textColor = UIColor.MCGray_middle
        return label
    }()
    
    public lazy var statusLabel: UILabel = {
        let label = UILabel.init()
        label.font = MCFont(13)
        label.textColor = UIColor.MCMain
        return label
    }()
    
    public lazy var wayLabel: UILabel = {
        let label = UILabel.init()
        label.font = MCFont(13)
        label.textColor = MCColor_16(colorStr: "fea54b")
        return label
    }()
    

}
